let dataSource = require('../service/dataSource');
let sql = require('../service/zstxSql');

class Zstx {

    hello(req, res, next) {
        console.log('HELLO......');
        res.render('book', {title: 'BOOK'});
    }

    getAdminList(req, res, next) {
        console.log('GETAdminList......\n'+sql.getAdminList);
        let offset = parseInt(req.query.offset) || 0
        console.log(sql)
        dataSource.query(sql.getAdminList(offset), function (err, result) {
            console.log(err)
            console.log(result)
            dataSource.jsonWrite(res, result);
        })
    }

    getContentList(req, res, next) {
        console.log('GETCONTENTLIST......');
        let offset = parseInt(req.query.offset) || 0
        dataSource.query(sql.getContentList(offset), function (err, result) {
            console.log(err)
            dataSource.jsonWrite(res, result);
        })
    }

    getTaskList(req, res, next) {
        let type, state, id = req.query
        console.log(type, state, id)
        dataSource.query(sql.myTask(type, state, id), function (err, result) {
            console.log(err);
            dataSource.jsonWrite(res, result)
        })
    }

    getTaskCount(req, res, next) {
        let type, state, id = req.query
        console.log(type, state, id)
        dataSource.query(sql.myTaskCount(type, state, id), function (err, result) {
            console.log(err);
            dataSource.jsonWrite(res, result)
        })
    }

    rePublish(req, res, next) {
        let type, state, id = req.query
        console.log(type, state, id)
        dataSource.query(sql.myTaskCount(type, state, id), function (err, result) {
            console.log(err);
            dataSource.jsonWrite(res, result)
        })
    }

    // findById(req, res, next) {
    //     console.log('findById.');
    //     let bookId = req.params.bookId;
    //     dataSource.query(sql.findById(bookId), function (err, result) {
    //         console.log(result[0]);
    //         dataSource.jsonWrite(res, result);
    //     })
    // }
}

module.exports = new Zstx();